/*
 * Copyright (c) 2011-2012 Alexander Dubu
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * o  Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * o  Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * o  Neither the name Axil nor the names of its contributors may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package axil.api.access;

import axil.api.Context;


/**
 * A host application object implements this interface when it cannot use the
 * field-level annotations. It is up to the host application to define how
 * fields are accessed when this mechanism is used. This interface may be mixed
 * with use of the @AccessibleType annotation when a hybrid model is desired.
 * <p/>
 * 	The name of an identifier referenced in the source can be any of the
 * 	following:
 * 	<ul>
 * 	    <li>A simple identifier. This is an identifier that does not contain
 * 	    	any '.' characters, typically meaning it can be looked-up
 * 	    	directly via a map. For example, 'shopping-cart'.</li>
 * 	    <li>A compound identifier. This is an identifier that contains
 * 	    	one or more '.' characters, indicating there is a navigation
 * 	    	path from a root host object being traversed. For example,
 * 	    	'shopping-cart.items'. In this example, the host application
 * 	    	object in the context is 'shopping-cart', and the 'items' field
 * 	    	within that object is to be accessed.</li>
 * 	    <li>An identifier containing non-traditional characters. An Axil
 * 	    	identifier can contain spaces or other punctuations characters.
 * 	    	For example, `last item purchased` (note that back-tick
 * 	    	characters) could be specified. It is up to the host application
 * 	    	to decide what is considered acceptable by returning an
 * 	    	appropriate value from this method.</li>
 * 	</ul>
 * This interface is intended to be implemented by host applications, as
 * necessary.
 */
public interface Accessible {
	/**
	 * Get an accessor for the given field residing within this object. If the
	 * field cannot be found, then an exception is thrown.
	 *
	 * @param context
	 * 	The context being used for the access.
	 *
	 * @param field
	 * 	The name of the field as it appears in the Axil script. Note that Axil
	 * 	supports a highly flexible identifier mechanism, allowing spaces and
	 * 	punctuation in identifiers. It is the responsibility of the host
	 * 	application to define how identifiers from Axil are mapped to actual
	 * 	object fields.
	 *
	 * @return
	 * 	Returns a non-null accessor object if the requested field is valid. A
	 * 	null may be returned if the field is not valid. The	returned object will
	 * 	be retained indefinitely by the caller and reused for subsequent accesses
	 * 	to the same field for objects of this type.
	 */
	public Accessor accessor(Context context, String field);
}
